﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;

namespace Jermaine
{
    public class Log
    {
        private static readonly String DefaultKey;
        private static readonly Log _Log;

        static Log() {
            _Log = new Log();
            DefaultKey = "Default";
        }

        private Log() { }

        public static Log Instance {
            get {
                return _Log;
            }
        }

        /// <summary>
        /// 默认实例
        /// </summary>
        public static Logger Default {
            get { return GetInstance(DefaultKey); }
        }

        private static Logger GetInstance(string key) {
            if (ObjectFactory.Exists<Logger>(key)) {
                return ObjectFactory.Get<Logger>(key);
            }
            var instance = LogManager.GetLogger(key);
            ObjectFactory.Put<Logger>(key, instance);
            return instance;
        }
        /// <summary>
        /// 获取实例
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public Logger this[string key] {
            get {
                return GetInstance(key);
            }
        }
    }
}
